package com.michael.study.listview

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

/**
 * Description:
 *
 * Created by liuguoquan on 2020/7/24 23:04.
 */
open class LinearAdapter(val context: Context, var datas: ArrayList<String>) :
    RecyclerView.Adapter<LinearAdapter.MyViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        Log.d("lgq", "onCreateViewHolder: ")
        var inflater = LayoutInflater.from(context);
        return MyViewHolder(inflater.inflate(R.layout.list_item_name, parent, false));
    }

    override fun getItemCount(): Int {
        return datas.size
    }

    override fun getItemViewType(position: Int): Int {
        return super.getItemViewType(position)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        Log.d("lgq", "onBindViewHolder: $position")
        holder.nameView.text = datas[position]
    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        public var nameView: TextView = itemView.findViewById(R.id.tv_name)


    }
}